package org.my.back;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
class LogAspect {

    @Around("execution(* *.*.MyService2.doHello(..))")
    Object logBefore(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("spring aop: Logging before method execution.");
        Signature signature = joinPoint.getSignature();
        String name = signature.getName();
        String declaringTypeName = signature.getDeclaringTypeName();
        Class declaringType = signature.getDeclaringType();
        MethodSignature signature1 = (MethodSignature) signature;
        Method method = signature1.getMethod();

        System.out.println(method);
        System.out.println(declaringType);
        System.out.println(declaringTypeName);
        System.out.println(name);

        return joinPoint.proceed();
    }
}
